import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:note/common/common.dart';
import 'package:note/common/info.dart';
import 'package:note/manager/global.dart';
import 'package:note/manager/init.dart';
import 'package:note/pages/root/logic.dart';
import 'package:note/routeConfig.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await InitApp.init();
  _showRootPage();
}

void _showRootPage() {
  if (GlobalUtil.appSet.value.isLocked) {
    runApp(const MyApp(page: RootPageNameUnlock));
  } else {
    runApp(const MyApp(page: RootPageNameHome));
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key, required this.page});
  final String page;
  @override
  Widget build(BuildContext context) {
    Get.lazyPut(() => RootLogic());
    return GetMaterialApp(
      title: GlobalUtil.packageInfo?.appName ?? Info.appName,
      theme: ThemeData(canvasColor: Styles.lightColor),
      getPages: RouteConfig.getPages,
      initialRoute: RouteConfig.rootPage,
      onInit: () {
        Get.find<RootLogic>().setPage(page);
      },
    );
  }
}
